package Solutions

/**
 * Definition for singly-linked list.
 * type ListNode struct {
 *     Val int
 *     Next *ListNode
 * }
 */
func deleteMiddle(head *ListNode) *ListNode {
	tHead := &ListNode{}
	tHead.Next = head
	last := tHead
	slow, fast := head, head
	for {
		if fast.Next != nil {
			if fast.Next.Next != nil {
				fast = fast.Next.Next
				last = slow
				slow = slow.Next
			} else {
				last = slow
				slow = slow.Next
				break
			}
		} else {
			break
		}
	}
	last.Next = slow.Next
	return tHead.Next
}
